package cn.chi.org.service.impl;

import cn.chi.org.domain.Department;
import cn.chi.org.mapper.DepartmentMapper;
import cn.chi.org.query.DepartmentQuery;
import cn.chi.org.service.IDepartmentService;
import cn.chi.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Transactional
    @Override
    public void save(Department department) {
        departmentMapper.save(department);
    }
    @Transactional
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        departmentMapper.remove(id);
    }

    @Override
    public Department queryById(Long id) {
        return departmentMapper.listById(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.listAll();
    }

    @Override
    public PageInfo<Department> queryPage(DepartmentQuery query) {
        //查询总条数
        Long count = departmentMapper.count(query);
        List<Department> list = departmentMapper.queryDate(query);
        return new PageInfo<>(count,list);
    }

    @Override
    public void patchDelete(Long[] ids) {
        departmentMapper.patchDelete(ids);
    }

    @Override
    public List<Department> getTree() {
        return departmentMapper.getTree();
    }
}
